﻿@page "/dialog"

@inject DialogService dialogService

<RadzenExample Name="Dialog" Documentation="true">
<div class="row">
    <div class="col-md-6">
        <h3>Dialog</h3>
        <RadzenButton Text=@($"Show OrderID: {orderID} details") Click="@(args => dialogService.Open<DialogCardPage>($"Order {orderID}",
                        new Dictionary<string, object>() { { "OrderID", orderID } },
                        new DialogOptions(){ Width = "700px", Height = "530px", Left = "calc(50% - 350px)", Top = "calc(50% - 265px)" }))" />
    </div>
    <div class="col-md-6">
        <h3>Events</h3>
        <RadzenCard style="overflow: auto;height:500px;">
            @foreach (var e in events.OrderByDescending(i => i.Key))
            {
                @e.Value
                <br />
            }
        </RadzenCard>
    </div>
</div>
</RadzenExample>

@code {
    int orderID = 10248;

    Dictionary<DateTime, string> events = new Dictionary<DateTime, string>();

    protected override void OnInitialized()
    {
        dialogService.OnOpen += Open;
        dialogService.OnClose += Close;
    }

    async void Open(string title, Type type, Dictionary<string, object> parameters, DialogOptions options)
    {
        events.Add(DateTime.Now, "Dialog opened");
        await InvokeAsync(() => { StateHasChanged(); });
    }

    async void Close(dynamic result)
    {
        events.Add(DateTime.Now, "Dialog closed. Result: " + result);
        await InvokeAsync(() => { StateHasChanged(); });
    }
}
